
const { resolve } = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");
const TerserPlugin = require("terser-webpack-plugin");

/** 配置导出函数
 * @param {Event} _env 
 * @param {import('webpack').Configuration} argv 
 * @returns {import('webpack').Configuration}
 */
module.exports = function (_env, argv) {
  return {
    // mode: "production",
    mode: "development",
    entry: "./src/index.ts",

    devtool: false,
    output: {
      path: resolve(__dirname, "./dist"),
      filename: "index.js"
    },
    module: {
      rules: [
        {
          test: /\.js$/,
          exclude: /node_modules/,
          use: [{
            loader: "babel-loader",
            options: {
              presets: [
                [
                  "@babel/preset-env",
                  {
                    targets: "node 16",
                  },
                ],
              ],
            },
          }],
        },
        {
          test: /\.ts$/,
          exclude: /node_modules/,
          use: { loader: "ts-loader", },
        },
      ]
    },
    plugins: [
      // new TerserPlugin({
      //   terserOptions: {
      //     compress: {
      //       drop_console: true,
      //     },
      //   },
      // }),
      new CleanWebpackPlugin(),
    ],
    target: "node"
  };
};
